<%-- 
    Document   : RecoverPasswordAction
    Created on : Nov 16, 2013, 11:00:15 PM
    Author     : smarzoug
--%>

<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@ page language="java"%>
<%@ page import="ece.fr.edu.fac.utilisateur.modele.Profil,ece.fr.edu.fac.utilisateur.oad.SécuritéDAO,ece.fr.edu.fac.controleur.outils.LoggerM" %>
<%
	String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE html>
<html>
    <head>
        <base href="<%=basePath%>">
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>RecoverPasswordAction.jsp</title>
    </head>
    <body>
        <%
            String target = "Recoverpasswordfprm.jsp?status=Entries not Matched... Try Again";;
            try{
                Profil rb=new Profil();
                String loginid=request.getParameter("username");
                String sanswer=request.getParameter("sanswer");
                rb.setLoginID(loginid);
                rb.setSecretAnswer(sanswer);
                int squestid=0;
                String password="";
                 if(request.getParameter("ch")!=null)
                {
                    rb.setSecretQuestionID(squestid);
                    rb.setOwnSecretQuestion(request.getParameter("ownquest"));
                    password=new SécuritéDAO().recoverPasswordByOWNQuestion(rb);
                }
                else
                {
                    squestid=Integer.parseInt(request.getParameter("squest"));
                    rb.setSecretQuestionID(squestid);
                    rb.setOwnSecretQuestion("Not Mentioned");
                    password=new SécuritéDAO().recoverPasswordByExistQuestion(rb);
                }
                if(password.equals("") || password==null)
                    target="Recoverpassword.jsp?status=Entries not Matched... Try Again";
                else
                   target="LoginForm.jsp?status=Password is "+password;
              }
              catch(Exception e)
              {
                 LoggerM.writeLogSevere(e);
              }
        RequestDispatcher rd = request.getRequestDispatcher(target);
        rd.forward(request,response);
        %>
    </body>
</html>
